package com.mq.route;

import com.mq.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class SendRoute {

    private static final String EXCHANGE_NAME = "test_exchange_direct";

    public static void main(String args[]) throws IOException, TimeoutException {

        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME,"direct");

        String msg = "new info!";

        String routingKey = "info";

        channel.basicPublish(EXCHANGE_NAME,routingKey,null,msg.getBytes());

        String msg2 = "new  warn";

        String routingKey2 = "warning";

        channel.basicPublish(EXCHANGE_NAME,routingKey2,null,msg2.getBytes());

        System.out.println("send "+ msg);
        channel.close();
        connection.close();
    }
}